package drds.datasource.connection_pool.util;


//import drds.common.Constants;

import drds.datasource.connection_pool.api.SqlException;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import tool.plus.Constants;

import java.sql.SQLException;

@Slf4j
public class JdbcUtils {
    public static void log(Logger log, String method, SQLException e) {
        if (Constants.developMode) {
            e.printStackTrace();
        }
        log.error(method, e);
    }

    public static void close(java.sql.Connection connection) throws SqlException {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                log(log, "connection.close()", e);
                //
                throw new SqlException(e);
            }
        }
    }

    public static void close(java.sql.Statement statement) throws SqlException {
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                log(log, "statement.close()", e);
                //
                throw new SqlException(e);
            }
        }
    }

    public static void close(java.sql.ResultSet resultSet) throws SqlException {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                log(log, "resultSet.close()", e);
                //
                throw new SqlException(e);
            }
        }
    }
}
